<?php

namespace apiend\modules\setting\models;

use Yii;
use common\models\shop\ShopStoreExpress;

/**
 * This is the model class for table "{{%base_express}}".
 *
 * @author emhome <emhome@163.com>
 * @since 1.0
 */
class StoreExpressForm extends \common\base\Model {

    public $store_id;
    public $express_id;

    /**
     * {@inheritdoc}
     */
    public function rules() {
        return [
            [['store_id', 'express_id'], 'integer'],
        ];
    }

    public function save() {
        if (!$this->validate()) {
            return $this->dumpError();
        }
        $model = ShopStoreExpress::findOrNew([
            'store_id' => $this->store_id,
            'express_id' => $this->express_id,
        ]);
        if ($model->isNewRecord) {
            if (!$model->save()) {
                return $model->dumpError();
            }
            return true;
        } else {
            if (!$model->delete()) {
                return $model->dumpError();
            }
            return false;
        }
    }

}
